/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import entities1.Users;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;


/**
 *
 * @author takamflore
 */
@Stateless
public class UserDaoImpl implements UserDao {
    
    @PersistenceContext(unitName = "meteoCal_PU")
    private EntityManager em;
List<Users> users;
Users user;

   @Override
    public void addUser(Users user) {
        em.persist(user);
   }

    @Override
    public List<Users> getAllUser() {      
                users=em.createNamedQuery("Users.findAll").getResultList();
        return users;
    } 
 @Override
    public void updateUserProfile(Users user) {
        em.merge(user);
        
    }    
  //
  @Override  
  public int checkUserLogin(String email,String password){
    int count=0;
    user= getUserEmail(email);
     if(user.getPassword().equals(password)){
         count=1;
     }
      return count;
  }
  //
  @Override
   public int getUserId(String userName){
       int userId;
   userId=em.createNamedQuery("Users.findByUserName").getFirstResult();
   return userId;
   }
   
   @Override
   public Users getUser(int userId){
      
               user=em.find(Users.class, userId);
       return  user;
   }
   @Override
   public void retrievePassword(String email){
       
   }
   @Override
   public Users getUserEmail(String email){
       user=em.find(Users.class,email);
       return user;
   }
 
}
